package com.vvhrad.javaagent.test01;

import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.VirtualMachineDescriptor;

import java.util.List;

/**
 * @author zhangqirong
 * @Date 2022/4/4
 */
public class Test {

    public static void main(String[] args) {
        System.out.println("agent main test");
        try {
            List<VirtualMachineDescriptor> virtualMachineDescriptorList = VirtualMachine.list();
            String pid = "";
            for (VirtualMachineDescriptor descriptor : virtualMachineDescriptorList) {
                System.out.println(descriptor.id() + "," + descriptor.displayName());
                pid = descriptor.id();
            }
            System.out.println(pid);
            VirtualMachine vm = VirtualMachine.attach(pid);
            vm.loadAgent("E:\\Idea\\java-agent-demo\\java-agent-demo-agent\\target\\java-agent-demo-agent-1.0.0-SNAPSHOT-jar-with-dependencies.jar");
        } catch (Exception e) {
            e.printStackTrace();
        }

        while (true) {

        }
    }

}
